﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Week6Music_API_and_Angular_.Adapter.Interfaces;
using Week6Music_API_and_Angular_.Data;
using Week6Music_API_and_Angular_.Models;

namespace Week6Music_API_and_Angular_.Adapter.Adapter
{
    public class EventAdapter : IEventAdapter
    {
        public List<EventVM> GetAllEvents()
        {
            List<EventVM> model;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                model = db.Events.Select(x => new EventVM()
                {
                    Id = x.Id,
                    FeaturedArtistID = x.FeaturedArtistID,
                    FeaturedArtist = x.FeaturedArtist.Name,
                    OpeningArtist = x.OpeningArtist.Name,
                    EventName = x.EventName,
                    EventPoster = x.EventPoster,
                    Date = x.Date,
                    ZipCode = x.ZipCode,
                    price = x.price
                }).ToList();
            }
            return model;
        }

        public EventVM GetEvent(int id)
        {
            EventVM model;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                model = db.Events.Where(x => x.Id == id).Select(x => new EventVM()
                    {
                        Id = x.Id,
                        EventName = x.EventName,
                        EventPoster = x.EventPoster,
                        Date = x.Date,
                        ZipCode = x.ZipCode,
                        price = x.price,
                        FeaturedArtist = x.FeaturedArtist.Name,
                        OpeningArtist = x.OpeningArtist.Name
                    }).FirstOrDefault();
            }
            return model;
        }
    }
}